<template>
    <view>
        <view v-if="isLoad === null" class="margin-top load notexist text-l text-grey"></view>
        <view v-if="isLoad === false" class="margin-top load loading text-l text-grey"></view>

        <view v-if="isLoad && isAdmin" class="main-admin">
            <view class="admin-comm-list">
                <view class="item">
                    <view class="info">
                        <view class="info-item">
                            <view class="title">用户昵称</view>
                            <view class="mao">：</view>
                            <view class="content text-admin text-l">{{ user.username }}</view>
                        </view>
                        <view class="info-item" @tap="url" data-type="phone" :data-url="user.phone">
                            <view class="title">手机号码</view>
                            <view class="mao">：</view>
                            <view class="content">
                                {{ user.phone }}
                                <text class="icon-phone text-l margin-left-xs"></text>
                            </view>
                        </view>
                        <view class="info-item">
                            <view class="title">注册时间</view>
                            <view class="mao">：</view>
                            <view class="content">{{ user.createdTime }}</view>
                        </view>
                    </view>
                </view>
            </view>
            <view style="height: 30rpx"></view>

            <!-- parse <template is="adminFormsDetailTpl" :data="forms:user.USER_FORMS"/> -->
            <block name="adminFormsDetailTpl">
                <view class="admin-comm-list" v-if="user && user.formList && user.formList.length > 0">
                    <view class="item">
                        <view class="info">
                            <view class="info-item info-item-solid" v-if="item.type != 'line'" v-for="(item, index) in user.formList" :key="index">
                                <view class="title">{{ item.title }}</view>

                                <view class="mao">：</view>

                                <view v-if="item.type == 'image'" class="content">
                                    <image
                                        @tap="url"
                                        data-type="image"
                                        :data-url="itm"
                                        :src="itm"
                                        mode="aspectFill"
                                        class="loading"
                                        :show-menu-by-longpress="true"
                                        v-for="(itm, index1) in item.val"
                                        :key="index1"
                                    ></image>
                                </view>

                                <view v-else-if="item.type == 'rows'" class="content" style="flex-direction: column">
                                    <text v-for="(itm, index1) in item.val" :key="index1">
                                        <text>{{ itm.title }}</text>

                                        <text v-if="itm.val">- {{ itm.val }}</text>
                                    </text>
                                </view>

                                <view v-else-if="item.type == 'switch'" class="content">{{ item.val === true ? '是' : '否' }}</view>

                                <view @tap="url" data-type="copy" :data-url="item.val" v-else class="content">{{ item.val }}</view>
                            </view>
                        </view>
                    </view>
                </view>
            </block>
        </view>
    </view>
</template>

<script>
const AdminBiz = require('@/utils/comm/biz/admin_biz.js');
const pageHelper = require('@/utils/helper/page_helper.js');
const cloudHelper = require('@/utils/helper/cloud_helper.js');
const api = require('@/api/adminapi.js');

export default {
    data() {
        return {
            isLoad: false,

            user: {
                username: '',
                phone: '',
                createdTime: '',
                formList: []
            },

            isAdmin: '',

            itm: {
                title: '',
                val: ''
            }
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    async onLoad(options) {
        if (!AdminBiz.isAdmin(this)) {
            return;
        }
        if (!pageHelper.getOptions(this, options)) {
            return;
        }
        this.loadDetailFun();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    async onPullDownRefresh() {
        await this.loadDetailFun();
        uni.stopPullDownRefresh();
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
        loadDetailFun: async function () {
            if (!AdminBiz.isAdmin(this)) {
                return;
            }
            let id = this.id;
            if (!id) {
                return;
            }
            let params = {
                id
            };
            let opts = {
                hint: false
            };
            let user = await api.getUserDetail(params, opts);
            console.log('user', user);
            if (!user) {
                this.setData({
                    isLoad: null
                });
                return;
            }
            // let user = await cloudHelper.callCloudData('admin/user_detail', params, opts);
            // if (!user) {
            //     this.setData({
            //         isLoad: null
            //     });
            //     return;
            // }
            this.setData({
                isLoad: true,
                user
            });
        },

        url(e) {
            pageHelper.url(e, this);
        }
    }
};
</script>
<style>
@import './admin_user_detail.css';
/* @import 'undefine÷d'; */
</style>
